﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace WowGuildSite.Armory
{
    public enum ItemSocketType
    {
        Red,
        Blue,
        Yellow,
        Meta,
    }

    public class ArmoryItemSockets
    {
        private ItemSocketType[]    sockets;
        private ArmoryItemEnchant   matchEnchant;

        public  ItemSocketType[]    AvailableSockets
        {
            get { return sockets; }
        }

        public  ArmoryItemEnchant   MatchEnchant
        {
            get { return matchEnchant; }
        }
    
        internal static ArmoryItemSockets FromElement( XmlElement element )
        {
            if ( element == null )
            {
                return new ArmoryItemSockets();
            }

            ArmoryItemSockets sockets = new ArmoryItemSockets();

            IList<XmlElement> socketElements = ArmoryXmlUtility.GetChildElements(element, "socket");

            sockets.sockets = new ItemSocketType[socketElements.Count];
            for( int i = 0; i < socketElements.Count; i++ )
            {
                sockets.sockets[i] =
                    (ItemSocketType)
                    Enum.Parse(typeof (ItemSocketType),
                               ArmoryXmlUtility.GetElementAttributeText(socketElements[i], "color"), true);
            }

            sockets.matchEnchant =
                ArmoryItemEnchant.FromElement(ArmoryXmlUtility.GetChildElement(element, "socketMatchEnchant"));

            return sockets;
        }

        private ArmoryItemSockets()
        {
            sockets = new ItemSocketType[0];
        }
    }
}
